package h0708;

import java.util.Scanner;
import java.util.StringJoiner;
/**
  * @description 报数游戏
  * @author 不知名帅哥
  * @date 2024/7/30 23:07
  * @version 1.0
*/
public class ReportNumberGame {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();

        if (m <= 1 || m >= 100) {
            System.out.println("ERROR!"); //不符合
        } else {
            getResult(m);
        }
        sc.close();
    }


    private static void getResult(int m) {
        CycleLinkedList cycleLinkedList = new CycleLinkedList();
        //初始化
        for (int i = 1; i <= 100; i++) {
            cycleLinkedList.addNode(i);
        }
        Node cur = cycleLinkedList.head; //从head开始
        while (cycleLinkedList.size >= m) {
            for (int i = 1; i <= 3; i++) {
                if (i == 3) {
                    //如果是3，删除当前节点，返回下一个节点。即为下个回合的开始节点。
                    cur = cycleLinkedList.deleteNode(cur);
                } else {
                    cur = cur.next;
                }
            }
        }
        StringJoiner joiner=new StringJoiner(",");
        while (cur!=null&&cur.prev!=null&&cur.next!=null){
            joiner.add(cur.val+"");
            cur=cycleLinkedList.deleteNode(cur);
        }
        System.out.println(joiner.toString());
//        System.out.println(cycleLinkedList.toString());
    }

}

class Node {
    int val;
    Node prev;
    Node next;

    public Node(int val) {
        this.val = val;
        this.next = null;
        this.prev = null;
    }
}

class CycleLinkedList {
    int size;
   Node head;
    Node tail;

    public CycleLinkedList() {
        this.size=0;
        this.head=null;
        this.tail=null;
    }

    //添加节点
    public void addNode(int val) {
        Node newNode = new Node(val);

        if (size>0){
            tail.next=newNode;
            newNode.prev=tail;
        }else {
            head=newNode;
        }
        tail=newNode;
        tail.next=head;
        head.prev=tail; //成为循环链表
        size++;
    }

    //删除节点
    public Node deleteNode(Node node) {

        Node prev = node.prev;
        Node next = node.next;

        prev.next=next;
        next.prev=prev;
        node.prev=node.next=null;

        if (head==node){
            this.head=next;
        }

        if (tail==node){
            this.tail=prev;
        }
        size--;
        return next;  //返回删除节点的后继方便求解。
    }

    @Override
    public String toString() {
        StringJoiner sj = new StringJoiner(",");

        Node cur = this.head;
        for (int i = 0; i < this.size; i++) {
            sj.add(cur.val + "");
            cur = cur.next;
        }

        return sj.toString();
    }
}